package com.tarena.lbs.content.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.content.pojo.param.ArticleActionParam;
import com.tarena.lbs.content.pojo.param.ArticleContentParam;
import com.tarena.lbs.content.pojo.query.ArticleQuery;
import com.tarena.lbs.content.pojo.vo.ArticleActionPageResultVO;
import com.tarena.lbs.content.pojo.vo.ArticleVO;
import com.tarena.lbs.content.service.ArticleService;
import com.tarena.lbs.common.response.JsonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

/**
 * 文章业务模块接口
 */
@Slf4j
@RestController
@Tag(name = "文章相关功能接口")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @Operation(summary = "文章分页列表查询")
    @GetMapping("/admin/content/article/list")
    public JsonResult<PageResult<ArticleVO>> pageList(ArticleQuery articleQuery) throws BusinessException{
        PageResult<ArticleVO> pageResult = new PageResult<>() ;
        pageResult.setTotal(1L);
        pageResult.setPageSize(1);
        List<ArticleVO> articleVOList = articleService.selectList(articleQuery);
        pageResult.setObjects(articleVOList);
        return JsonResult.ok(pageResult);
    }


    @Operation(summary = "文章保存")
    @PostMapping("/admin/content/article/insert")
    public JsonResult<Void> addArticle(ArticleContentParam param) throws BusinessException{
       log.info("k保存文章信息: {}", param);
        articleService.save(param);
        return JsonResult.ok();
    }


    @Operation(summary = "文章标签集合")
    @GetMapping("/admin/content/article/getArticleLabel")
    public JsonResult<Set<String>> articleLabels(ArticleQuery articleQuery) throws BusinessException {

        return JsonResult.ok(null);
    }


    @Operation(summary = "文章详情")
    @GetMapping("/admin/content/article/get")
    public JsonResult<ArticleVO> articleDetail(String id)throws BusinessException{
        ArticleVO articleVO = articleService.selectById(id);
        return JsonResult.ok(articleVO);
    }


    @Operation(summary = "用户行为记录")
    @PostMapping("/admin/content/article/behavior")
    public JsonResult<Void> articleBehavior(ArticleActionParam param)
        throws BusinessException{
        return JsonResult.ok();
    }


    @Operation(summary = "查询已经点赞 收藏 访问过的文章")
    @GetMapping("admin/content/article/getBehaviorList")
    public JsonResult<ArticleActionPageResultVO> getBehaviorLists(ArticleQuery query)
        throws BusinessException{
        return JsonResult.ok(null);
    }
}
